# gozerlib/botbase.py
#
#

""" base class for all bots. """

## gozerlib imports

from config import cfg
from plugins import plugs
from less import Less
from callbacks import callbacks
from channelbase import ChannelBase

## basic imports

import time
import logging
import copy

cpy = copy.deepcopy

class BotBase(object):

    def __init__(self, name, *args, **kwargs):
        self.type = ""
        self.name = name
        self.nick = self.name
        self.starttime = time.time()
        self.outcache = Less(1)
        self.channels = {}

    def doevent(self, event):

        """ 
            dispatch an event. 

            :param event: event to dispatch.
            :rtype: None

        """

        if not event:
            return

        e = cpy(event)

        if event.channel and not self.channels.has_key(event.channel):
            self.channels[event.channel] = ChannelBase(event.channel, event.title, event.type)

        if event.channel:
            self.channels[event.channel].lastmodified = time.time()
            self.channels[event.channel].wholastmodified = event.userhost

        if event.txt and not event.isremote:
            plugs.dispatch(self, event)

        callbacks.check(self, e)
        
    def ownercheck(self, userhost):

        """
            check if provided userhost belongs to an owner. 

            :param userhost: userhost to check.
            :type userhost: string
            :rtype: boolean

        """

        if userhost in cfg['owner']:
            return True

        return False

    def say(self, channel, txt):

        """
            override this. 

            :param channel: channel to send txt to
            :type channel: string
            :param txt: text to send
            :type txt: string
            :rtype: None

        """

        pass

    def sayroot(self, channel, txt):

        """
            override this. 

            :param channel: channel to send txt to
            :type channel: string
            :param txt: text to send
            :type txt: string
            :rtype: None

        """

        pass
